Page({
  data: {
    statusBarHeight: 0,
    navbarHeight: 0,
    rewardSummary: {
      onTheWay: 1920.83,    // 在路上
      received: 12923.10,    // 已获得
      expired: 342.09        // 已失效
    },
    rewards: []
  },

  onLoad() {
    // 获取系统信息，用于适配状态栏高度
    try {
      const systemInfo = wx.getSystemInfoSync()
      const statusBarHeight = systemInfo.statusBarHeight || 0
      const navbarHeight = statusBarHeight + 44
      this.setData({
        statusBarHeight: statusBarHeight,
        navbarHeight: navbarHeight
      })
    } catch (e) {
      console.error('获取系统信息失败:', e)
      this.setData({
        statusBarHeight: 0,
        navbarHeight: 44
      })
    }

    this.loadRewards()
  },

  loadRewards() {
    // 加载奖励数据（这里使用模拟数据，实际应该从后端获取）
    const rewards = this.getMockRewards()
    
    // 格式化金额
    const formattedRewards = rewards.map(item => ({
      ...item,
      formattedOrderAmount: item.orderAmount.toFixed(2),
      formattedRewardAmount: item.rewardAmount.toFixed(2)
    }))

    // 使用固定的汇总数据（与设计图保持一致）
    const summary = {
      onTheWay: '1920.83',
      received: '12923.10',
      expired: '342.09'
    }

    this.setData({
      rewards: formattedRewards,
      rewardSummary: summary
    })
  },

  getMockRewards() {
    // 模拟奖励数据（用于演示）
    return [
      {
        id: 1,
        orderNo: '093132387126',
        orderAmount: 1092.00,
        rewardAmount: 11.90,
        status: 'onTheWay',
        date: '2019-06-19 08:21:09'
      },
      {
        id: 2,
        orderNo: '093132387931',
        orderAmount: 1009.00,
        rewardAmount: 10.09,
        status: 'onTheWay',
        date: '2019-06-19 08:21:09'
      },
      {
        id: 3,
        orderNo: '093132387126',
        orderAmount: 1092.00,
        rewardAmount: 11.90,
        status: 'onTheWay',
        date: '2019-06-19 08:21:09'
      }
    ]
  },

  goBack() {
    const pages = getCurrentPages()
    if (pages.length > 1) {
      wx.navigateBack()
    } else {
      wx.navigateTo({
        url: '/pages/my-wallet/my-wallet'
      })
    }
  }
})

